package com.korustar.autumnal.reflect;

import java.lang.reflect.Field;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Helper methods for setter injection
 * 
 * @author amir
 *
 */
public class FieldReflection {
	private static final Logger LOGGER = LoggerFactory.getLogger(FieldReflection.class);
	public static Class<?> getFieldType(String type, String fieldName) {
		Class<?> typeFromClasspath = ClassLoaderUtil.getClassFromClasspath(type);
		if(typeFromClasspath!=null) {
			Field[] fields = typeFromClasspath.getDeclaredFields();
			for (Field field : fields) {
				if(field.getName().equals(fieldName)) {
					LOGGER.info("Found field {}", field);
					return field.getType();
				}
			}
		} else {
			LOGGER.debug("NOT Found type ... {}", type);
		}
		return null;
	}
	public static String getSetter(String propertyName) {
		String SET = "set";
		String methodName= SET+propertyName.substring(0,1).toUpperCase()+propertyName.substring(1);
		return methodName;
	}
}
